const requestConfig = {
    serverUrl: "http://192.168.6.222:9002/"
};

const ajax = (url, params, methos) => {
    wx.showLoading({
        title: "加载中...",
        mask: true
    })

    return new Promise((resolve, reject) => {
        let header = {
            "content-type": "application/json"
        };
        let authorization = wx.getStorageSync("authorization");
        if (Boolean(authorization)) {
            header.Authorization = authorization;
        }
        wx.request({
            url: requestConfig.serverUrl + url,
            data: params,
            method: methos,
            header: header,
            success(res) {
                if (res.data.code === 200) {
                    console.log("接口【 " + url + " 】请求成功！返回参数为 ↓↓↓");
                    console.log(res.data);
                    resolve(res.data);
                } else {
                    reject(res.data);
                }
            },
            fail(error) {
                console.log("请求失败!");
                reject(error);
            },
            complete(info) {
                wx.hideLoading();
            }
        })
    })
}

export default {
    ajax
}
